package com.shameit.goodqrinfomanager.ui.activity.cangku;

import android.app.Application;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.shameit.goodqrinfomanager.adapter.ChukuAdapter;
import com.shameit.goodqrinfomanager.bean.litepal.CangKu;
import com.shameit.goodqrinfomanager.bean.litepal.CangWei;
import com.shameit.goodqrinfomanager.source.http.DataRepository;
import com.shameit.goodqrinfomanager.ui.activity.chuku.ChukuActivity;
import com.shameit.goodqrinfomanager.ui.activity.offline.OfflineManagementActivity;

import org.litepal.LitePal;

import java.util.List;

import me.goldze.mvvmhabit.base.BaseModel;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class CangkuManagementViewModel extends BaseViewModel<DataRepository> {

    public ObservableField<String> cwbh = new ObservableField<>("");
    public ObservableField<String> czlx = new ObservableField<>("");




    public CangkuManagementViewModel(@NonNull Application application, DataRepository model) {
        super(application, model);
    }

    public BindingCommand gotoRuku = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putString("cangwei",cwbh.get());
            if ("入库".equals(czlx.get())) {
                startActivity(ChukuActivity.class, bundle);
            } else {
                //出库
            }
        }
    });

    public BindingCommand gotoOffline = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            startActivity(OfflineManagementActivity.class);
        }
    });

    public String[] loadCangkuItem(){
        List<CangKu> cangKuList = LitePal.order("warehouseNo").find(CangKu.class);
        String[] ckArr = new String[cangKuList.size()];
        for (int i = 0; i < cangKuList.size(); i++) {
            ckArr[i] = cangKuList.get(i).getWarehouseNo();
        }
        return ckArr;
    }

    public String[] loadCangweiItem(String cangkucode){
        List<CangWei> cangWeiList = LitePal.where("warehouseNo = ? ", cangkucode).order("placeNo").find(CangWei.class);
        String[] cwArr = new String[cangWeiList.size()];
        for (int i = 0; i < cangWeiList.size(); i++) {
            cwArr[i] = cangWeiList.get(i).getPlaceNo();
        }
        return cwArr;
    }

}
